package com.qf.rabbitmq.util;


import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionUtil {

    public static Connection getConnection(){
//        创建Connection  工厂
        ConnectionFactory factory=new ConnectionFactory();
//        设置地址
        factory.setHost("10.9.45.217");
//        设置 端口   默认也是5672
        factory.setPort(5672);
//        设置虚拟主机 名
        factory.setVirtualHost("/test");

//        设置账号密码
        factory.setUsername("test");
        factory.setPassword("test");


//        获取连接
        Connection connection=null;
        try {
            connection = factory.newConnection();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
        return connection;

    }
}
